package com.mop.app.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import com.mop.app.dal.entity.AppBug;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mop.app.common.PageQueryWrapper;

import org.springframework.web.bind.annotation.RestController;
import com.mop.app.common.BaseController;
import com.mop.app.service.AppBugService;

import java.util.List;
/**
 * bug反馈记录
 *
 * @author wchen
 * @since 2020-02-27
 */
@RestController
@RequestMapping("/open/bug")
public class BugController extends BaseController {

    @Autowired
    private AppBugService appBugService;


    /**
     * 保存或新增
     *
     * @param appBug
     * @return
     */
    @PostMapping("/saveOrUpdate")
    public AppBug saveOrUpdate(@RequestBody AppBug appBug) throws Exception {
        if (appBugService.saveOrUpdate(appBug)) {
            return appBug;
        }
        throw new Exception();
    }
    /**
     * 分页查询
     *
     * @param query 默认使用实体作为查询参数，可根据业务需要替换为查询对象，如若替换为查询对象，请修改相应mapper文件的sql查询
     * @return 分页结果集
     */
    @PostMapping("/list")
    public Page<AppBug> list(@RequestBody PageQueryWrapper<AppBug> query) {

        query.setQueryClazz(AppBug.class);
        Page pageList = appBugService.pageQuery(query);

        return pageList;
    }
    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    @PostMapping("/remove")
    public void remove(@RequestBody List<Long> idList) throws Exception {
        if (appBugService.removeByIds(idList)) {
            return;
        }
        throw new Exception();
    }

    /**
     * 单条记录查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AppBug getById(@PathVariable Long id) {
        AppBug appBug = appBugService.getById(id);
        return appBug;
    }
}

